package util;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class IOOperater {
	
	/**
	 * 调用Scanner来读取输入
	 */
	public List<Integer> readInputsbyScanner(){
		List<Integer> origin = new ArrayList<Integer>();

		Scanner reader = new Scanner(System.in);
		System.out.print("后续" + reader.hasNext());
		int i = 0;
		while (true) {
			int n = reader.nextInt();
			// 以0为输入结束的标志位, 对0需要做特殊处理
			if (n == 0 && !reader.hasNext()) {
				break;
			}

			origin.add(n);
			

		}

		System.out.println("刚刚输入: " + origin.size());
		for (int j = 0; j < origin.size(); j++) {
			System.out.println(origin.get(j) + " ");
		}
		
		return origin;
	};
	
	/**
	 * 调用Buffer来读取输入
	 */
	public List<Integer> readInputsbyBuffer(){
		List<Integer> origin = new ArrayList<Integer>();
		BufferedReader buffer = new BufferedReader(new InputStreamReader(
				System.in));
		System.out.println("请输入一串字符串");
		String text = new String();
		try {
			text = buffer.readLine();
		} catch (IOException e) {
			e.printStackTrace();
		}

		System.out.println("您输入的字符串是:");
		String[] s = text.split(" ");
		for (int i = 0; i < s.length; i++) {
			origin.add(Integer.parseInt(s[i]));
			System.out.print(origin.get(i) + "  ");
		}

		return origin;
	};

}
